﻿
@{
    Layout = "~/Views/Shared/_Edit.cshtml";
}
@model DTO.DTO.Sys.AdminUser.AdminUserDetailDTO
<form class="layui-form" action="" style="margin-top:20px;">
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="UserName" lay-verify="required" autocomplete="off" placeholder="用户名" class="layui-input" value="@Model.UserName" @(string.IsNullOrWhiteSpace(Model.Id) ? "" : "disabled")>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="Password" lay-verify="pass" placeholder="密码" autocomplete="off" class="layui-input" value="@Model.Password">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到20位密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="SurName" lay-verify="required" autocomplete="off" placeholder="姓名" class="layui-input" value="@Model.SurName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">城市</label>
        <div class="layui-input-inline">
            <input type="text" name="City" autocomplete="off" placeholder="城市" class="layui-input" value="@Model.City">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-inline">
            <input type="text" name="Department" autocomplete="off" placeholder="部门" class="layui-input" value="@Model.Department">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-inline">
            <input type="text" name="Post" autocomplete="off" placeholder="职位" class="layui-input" value="@Model.Post">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="Email" lay-verify="email" placeholder="邮箱" autocomplete="off" class="layui-input" value="@Model.Email">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">固定电话</label>
        <div class="layui-input-inline">
            <input type="text" name="Tel" placeholder="固定电话" autocomplete="off" class="layui-input" value="@Model.Tel">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-inline">
            <input type="text" name="Mobile" lay-verify="phone" placeholder="手机" autocomplete="off" class="layui-input" value="@Model.Mobile" maxlength="11">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">超级管理员</label>
        <div class="layui-input-inline">
            <input type="checkbox" @(Model.IsAdmin == 1 ? "checked=''" : "") name="IsAdmin" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@section script{
    <script>
        layui.use("form", function () {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.$;

            var index = parent.layer.getFrameIndex(window.name);

            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                formData.IsAdmin = formData.IsAdmin === "on" ? 1 : 0;
                $.post("Save", formData, function (d) {
                    if (d.code === 0) {
                        layer.msg(d.msg, { icon: 1 });
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 1000);
                    }
                    else {
                        layer.msg(d.msg, { icon: 2 });
                    }
                })
                return false;
            });

            //自定义验证规则
            form.verify({
                pass: [/^\w{6,20}$/, '密码必须6到20位']
            });
        });
    </script>
}

